/**
 * Created by zxd on 2017/11/1.
 */
$(function(){

    //初始化日期控件
    $('#bt, #et').datetimepicker({
        language: 'zh-CN',
        format: 'yyyy-mm-dd',
        autoclose: true,
        minuteStep: 1,
        minView: "month"
    });

    loadDatas()
});


function loadDatas(s){

    if(s=="search"){
        $("#page").val("");
    }


    //页码
    var page = $("#page").val();
    //一页显示的条数
    var pageSize = 40;
    //用户类型
    var sType = $("#sType").val();
    //管理员用户
    var GmUser = $("#GmUser").val();
    //用户
    var UserID = $("#UserID").val();
    //添加开始时间
    var begin = $("#begin_time").val();
    //添加结束时间
    var end = $("#end_time").val();
    //金币变动类型
    var ScoreChangeType=$("#ScoreChangeType").val();
    //增加类型
    var cztype=$("#cztype").val();

    $.ajax({
        type:"post",
        data: {"page":page,"pageSize":pageSize,"sType":sType,"GmUser":GmUser,"UserID":UserID,"begin":begin,"end":end,"ScoreChangeType":ScoreChangeType,"cztype":cztype},
        url:"../../../php/sys/admin/adminAddMoneyLog.php",
        beforeSend: function(){
            $("#load").css("display","block");
        },success:function(msg){

            $("#load").css("display","none");

            var datas = msg.records;
            var html = "";
            if(datas.length==0){


                html += "<tr><td colspan='9' align='center'>没查询到符合条件的数据~</td></tr>";
            }else{

                for(var i=0;i<datas.length;i++){
                    html += "<tr>";
                    html += "<td>"+datas[i].id+"</td>";//id
                    html += "<td><a style='color:blue' href='../player/playerInfo/playerDetailsInfo.php?gameId="+datas[i].gameid+"' title='查看玩家详情'>"+datas[i].nickname+"</a></td>";//昵称
                    html += "<td><a style='color:blue' href='../player/playerInfo/playerDetailsInfo.php?gameId="+datas[i].gameid+"' title='查看玩家详情'>"+datas[i].gameid+"</a></td>";//推广号
                    html += "<td>"+datas[i].accounts+"</td>";//账号
                    html += "<td>"+datas[i].adminname+"</td>";//操作时间
                    var scoretype=datas[i].scoretype;
                    if(scoretype>0){
                        html += "<td>扣除  "+scoretype+"</td>";
                    }else if(scoretype<0){
                        html += "<td>添加  "+scoretype+"</td>";
                    }
                   //操作ip
                    var type=datas[i].cztype;
                    if(type=="1"){
                        html += "<td>系统bug补偿</td>";//id
                    }else if(type=="2"){
                        html += "<td>活动赠送</td>";
                    }else if(type=="3"){
                        html += "<td>盗号问题</td>";
                    }else if(type=="4"){
                        html += "<td>其他</td>";
                    }

                    html += "<td>"+datas[i].writedate+"</td>";//管理员
                    html += "<td>"+datas[i].changeip+"</td>";//操作内容
                    html += "<td>"+datas[i].memo+"</td>";//操作时间


                    html += "</tr>";

                }

            }
            $("#databody").html(html);
            //金币数
            $("#scores").html(msg.czjb==""?0:msg.czjb);//金币数
            //$("scores").html(datas[i].czjb);

            //分页数据
            var pageInfos = msg.pageInfo;
            //总条数
            var allCount = pageInfos[0].count;
            $("#count").html(allCount);
            //总页数
            var allPage = Math.ceil(allCount/pageSize);
            if(allPage==0){
                allPage = 1;
            }
            //当前页码
            var now = pageInfos[0].page;

            $("#page").val(now);
            $("#nowPage").html(now);
            $("#allPage").html(allPage);
            $("#pageIpu").val("");

        },error:function(msg){
            console.log(msg);
            alert("连接出错！");
        }
    });


}



function findAll(s){
    $("#load").css("display","block");

    $("#reset").click();

    loadDatas(s);
}



